/*
 * DefaultInstruction.java
 * 
 * last update: 16.01.2010 by Stefan Saru
 * 
 * author:	Alec(panovici@elcom.pub.ro)
 * 
 * Obs:
 */


package engine;

/**
 * This class is the parent of all 'user' instructions
 * (i.e. those which have a corespondent into the user's code
 */
public abstract class DefaultInstruction extends Instruction{

	/**
	 * the NameSpace instance wich contains this instruction
	 */
	NameSpace ns;

	/**
	 * what d'u think it is ??
	 */
	int  delayBefore;

	/**
	 * this instruction's description
	 */

	InstructionDescription desc;

	/**
	 * used by branch instructions.
	 */
	int state;

	DefaultInstruction(NameSpace ns, int delayBefore,
			InstructionDescription desc){
		this.ns = ns;
		this.delayBefore = delayBefore;
		this.desc = desc;
		state = 0;
	}

	long waitToRun()
	throws SimulationStoppedException
	{
		long t0 = Time.oClock();
		if(delayBefore != 0){
			t0 += delayBefore;
			xConsole.trace(this + " >>> #" + delayBefore);
			while(Time.oClock() < t0) {
				ControlThread.goSleepy();
			}
		}
		return t0;
	}

	public String toString(){
		return desc.toString();
	}

	/**
	 * Should throw an exception if this this
	 * instruction does not satisfy the function
	 * instructions' restrictions
	 */
	void checkIfIsAllowedInFunction()
	throws ParseException
	{}


}

